package com.autodesk.utility;

import java.net.URL;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;


import android.app.Activity;
import android.os.Bundle;

public class XmlReader extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        try {
			
			/** Handling XML */
			SAXParserFactory spf = SAXParserFactory.newInstance();
			SAXParser sp = spf.newSAXParser();
			XMLReader xr = sp.getXMLReader();

			/** Send URL to parse XML Tags */
			URL sourceUrl = new URL("http://poleview.googlecode.com/files/feature_sample.xml");
		//	URL sourceUrl = new URL(
		//	"http://www.androidpeople.com/wp-content/uploads/2010/06/example.xml");

			/** Create handler to handle XML Tags ( extends DefaultHandler ) */
			FeatureXMLHandler myXMLHandler = new FeatureXMLHandler();
			xr.setContentHandler(myXMLHandler);
			InputSource inputSource = new InputSource(sourceUrl.openStream());
			//inputSource.setEncoding("UTF-8");
			xr.parse(inputSource);
			
		} catch (Exception e) {
			System.out.println("XML Pasing Excpetion = " + e);
		}
        
    }
}